﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;
public partial class Report_MonthDepartment : System.Web.UI.Page
{
    DepartmentInfoManager dllDepartment = new DepartmentInfoManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    MonthPlanManager dllMonthPlanManager = new MonthPlanManager();
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    Authentication dllAuthentication = new Authentication();
    VerifyCircuitManager dllVerifyCircuitManager = new VerifyCircuitManager();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    QuarterPlanofManager dllQuarterPlanofManager = new QuarterPlanofManager();
    ReportManager dllReportManager = new ReportManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //起始月的DropDownList绑定
            bindDropDownList(this.drpYearStart);
            bindDropDownList(this.drpQuarterDateStart);
            bindDropDownList(this.drpMonthDateStart);
            //结束月的DropDownList绑定
            bindDropDownList(this.drpYearEnd);
            bindDropDownList(this.drpQuarterDateEnd);
            bindDropDownList(this.drpMonthDateEnd);
        }
    }
    void bindDropDownList(DropDownList _drp)
    {

        //起始月的年份绑定
        if (_drp.Equals(this.drpYearStart))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            string _year = DateTime.Now.Year.ToString();
            this.drpYearStart.SelectedIndex = this.drpYearStart.Items.IndexOf(this.drpYearStart.Items.FindByText(_year));

        }
        //结束月的年份绑定
        if (_drp.Equals(this.drpYearEnd))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            string _year = DateTime.Now.Year.ToString();
            this.drpYearEnd.SelectedIndex = this.drpYearEnd.Items.IndexOf(this.drpYearEnd.Items.FindByText(_year));

        }

        //起始月的年计划周期绑定
        if (_drp.Equals(this.drpQuarterDateStart))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYearStart.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDateStart.DataSource = _quarter;
                this.drpQuarterDateStart.DataTextField = "QuarterName";
                this.drpQuarterDateStart.DataValueField = "Quarter_Id";
                this.drpQuarterDateStart.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                //根据系统当前日期查找到对应的年周期
                DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                //如果查到结果（结果只有一条）

                if (_quartertime.Rows.Count == 1)
                {
                    this.drpQuarterDateStart.SelectedIndex = this.drpQuarterDateStart.Items.IndexOf(this.drpQuarterDateStart.Items.FindByText(_quartertime.Rows[0][1].ToString()));
                    this.drpQuarterDateStart.DataSource = _quartertime;
                    this.drpQuarterDateStart.DataTextField = "QuarterName";
                    this.drpQuarterDateStart.DataValueField = "Quarter_Id";
                }
                #endregion
                bindDropDownList(this.drpMonthDateStart);
            }
            else
            {
                ListItem _li = new ListItem("无年周期");
                this.drpQuarterDateStart.Items.Clear();
                this.drpQuarterDateStart.Items.Add(_li);
                bindDropDownList(this.drpMonthDateStart);
            }
        }
        //结束月的年计划周期绑定
        if (_drp.Equals(this.drpQuarterDateEnd))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYearEnd.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDateEnd.DataSource = _quarter;
                this.drpQuarterDateEnd.DataTextField = "QuarterName";
                this.drpQuarterDateEnd.DataValueField = "Quarter_Id";
                this.drpQuarterDateEnd.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                //根据系统当前日期查找到对应的年周期
                DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                //如果查到结果（结果只有一条）

                if (_quartertime.Rows.Count == 1)
                {
                    this.drpQuarterDateEnd.SelectedIndex = this.drpQuarterDateEnd.Items.IndexOf(this.drpQuarterDateEnd.Items.FindByText(_quartertime.Rows[0][1].ToString()));
                    this.drpQuarterDateEnd.DataSource = _quartertime;
                    this.drpQuarterDateEnd.DataTextField = "QuarterName";
                    this.drpQuarterDateEnd.DataValueField = "Quarter_Id";
                }
                #endregion
                bindDropDownList(this.drpMonthDateEnd);
            }
            else
            {
                ListItem _li = new ListItem("无年周期");
                this.drpQuarterDateEnd.Items.Clear();
                this.drpQuarterDateEnd.Items.Add(_li);
                bindDropDownList(this.drpMonthDateEnd);
            }
        }

        //起始月的月计划周期绑定
        if (_drp.Equals(this.drpMonthDateStart))
        {

            object[] _value = new object[2];
            _value[0] = this.drpYearStart.SelectedValue;
            _value[1] = this.drpQuarterDateStart.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {
                this.drpMonthDateStart.DataSource = _month;
                this.drpMonthDateStart.DataTextField = "MonthName";
                this.drpMonthDateStart.DataValueField = "Month_Id";
                this.drpMonthDateStart.DataBind();
                #region 根据系统当前日期绑定到当前月周期
                DataTable _monthtime = dllMonthDateManager.getMonthDate();
                if (_monthtime.Rows.Count == 1)
                {
                    this.drpMonthDateStart.SelectedIndex = this.drpMonthDateStart.Items.IndexOf(this.drpMonthDateStart.Items.FindByText(_monthtime.Rows[0][3].ToString()));
                    this.drpMonthDateStart.DataSource = _monthtime;
                    this.drpMonthDateStart.DataTextField = "MonthName";
                    this.drpMonthDateStart.DataValueField = "Month_Id";

                }
                #endregion

            }
            else
            {
                ListItem _li = new ListItem("无月周期");
                this.drpMonthDateStart.Items.Clear();
                this.drpMonthDateStart.Items.Add(_li);
            }
        }
        //结束月的月周期绑定
        if (_drp.Equals(this.drpMonthDateEnd))
        {

            object[] _value = new object[2];
            _value[0] = this.drpYearEnd.SelectedValue;
            _value[1] = this.drpQuarterDateEnd.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {
                this.drpMonthDateEnd.DataSource = _month;
                this.drpMonthDateEnd.DataTextField = "MonthName";
                this.drpMonthDateEnd.DataValueField = "Month_Id";
                this.drpMonthDateEnd.DataBind();
                #region 根据系统当前日期绑定到当前月周期
                DataTable _monthtime = dllMonthDateManager.getMonthDate();
                if (_monthtime.Rows.Count == 1)
                {
                    this.drpMonthDateEnd.SelectedIndex = this.drpMonthDateEnd.Items.IndexOf(this.drpMonthDateEnd.Items.FindByText(_monthtime.Rows[0][3].ToString()));
                    this.drpMonthDateEnd.DataSource = _monthtime;
                    this.drpMonthDateEnd.DataTextField = "MonthName";
                    this.drpMonthDateEnd.DataValueField = "Month_Id";

                }
                #endregion

            }
            else
            {
                ListItem _li = new ListItem("无月周期");
                this.drpMonthDateEnd.Items.Clear();
                this.drpMonthDateEnd.Items.Add(_li);

            }

        }

    }
    #region
    /// <summary>
    /// 起始月的年份改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYearStart_SelectedIndexChanged(object sender, EventArgs e)
    {

        bindDropDownList(this.drpQuarterDateStart);
        bindDropDownList(this.drpMonthDateStart);
    }

    /// <summary>
    /// 起始月的年周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDateStart_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDateStart);
    }
    /// <summary>
    /// 起始月的月周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDateStart_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.btnQuery_Click(sender, e);
    }
    /// <summary>
    /// 结束月的年份改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYearEnd_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDateEnd);
        bindDropDownList(this.drpMonthDateEnd);
    }
    /// <summary>
    /// 结束月的年周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDateEnd_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDateEnd);
    }
    /// <summary>
    /// 结束月的月周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDateEnd_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.btnQuery_Click(sender, e);
    }
    #endregion

    /// <summary>
    /// 统计按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        ListItem _monthSatrt = this.drpMonthDateStart.SelectedItem;
        ListItem _monthEnd = this.drpMonthDateEnd.SelectedItem;
        ListItem _type = this.drpType.SelectedItem;
        if (_monthSatrt != null && _monthEnd != null && _type != null)
        {
            if (this.txtDepartment.Value.Length > 0)
            {
                if (_type.Text == "按部门查询")
                {
                    if (_monthSatrt.Text != "无月周期" && _monthEnd.Text != "无月周期")
                    {
                        DataSet ds = dllReportManager.getMonthDepartmentByDepartmentNames(Convert.ToInt32(_monthSatrt.Value), Convert.ToInt32(_monthEnd.Value), this.txtDepartment.Value);
                        this.gdvMonthDepartment.DataSource = ds.Tables[ds.Tables.Count - 1];
                        this.gdvMonthDepartment.DataBind();
                        this.txtDepartment.Value = "";
                        this.gdvMonthDepartmentCenter.Visible = false;
                        this.gdvMonthDepartment.Visible = true;
                    }
                }
                else
                {
                    if (_monthSatrt.Text != "无月周期" && _monthEnd.Text != "无月周期")
                    {
                        this.gdvMonthDepartmentCenter.DataSource = dllReportManager.getMonthDepartmentByCenterNames(Convert.ToInt32(_monthSatrt.Value), Convert.ToInt32(_monthEnd.Value), this.txtDepartment.Value);
                        this.gdvMonthDepartmentCenter.DataBind();
                        this.txtDepartment.Value = "";
                        this.gdvMonthDepartmentCenter.Visible = true;
                        this.gdvMonthDepartment.Visible = false;
                    }
                }
            }
            else
            {
                if (_type.Text == "按部门查询")
                {
                    string _department = dllDepartment.getAllDepartment();

                    if (_monthSatrt.Text != "无月周期" && _monthEnd.Text != "无月周期")
                    {
                        DataSet ds = dllReportManager.getMonthDepartmentByDepartmentNames(Convert.ToInt32(_monthSatrt.Value), Convert.ToInt32(_monthEnd.Value), _department);
                        this.gdvMonthDepartment.DataSource = ds.Tables[ds.Tables.Count - 1];
                        this.gdvMonthDepartment.DataBind();
                        this.txtDepartment.Value = "";
                        this.gdvMonthDepartmentCenter.Visible = false;
                        this.gdvMonthDepartment.Visible = true;
                    }
                }
                else
                {
                    string _center = dllDepartment.getAllCenter();
                    if (_monthSatrt.Text != "无月周期" && _monthEnd.Text != "无月周期")
                    {
                        this.gdvMonthDepartmentCenter.DataSource = dllReportManager.getMonthDepartmentByCenterNames(Convert.ToInt32(_monthSatrt.Value), Convert.ToInt32(_monthEnd.Value), _center);
                        this.gdvMonthDepartmentCenter.DataBind();
                        this.txtDepartment.Value = "";
                        this.gdvMonthDepartmentCenter.Visible = true;
                        this.gdvMonthDepartment.Visible = false;
                    }
                }
            }
        }

        if (_type.Text == "按部门查询")
        {
            AddHyperLink(this.gdvMonthDepartment);
        }
        else
        {
            //AddHyperLink(this.gdvMonthDepartmentCenter);
        }

        MergeRow(this.gdvMonthDepartment, 0);
        if (_type.Text == "按部门查询")
        {
            Process(this.gdvMonthDepartment);
        }
        else
        {
            //ProcessCenter(this.gdvMonthDepartmentCenter);
        }
    }

    /// <summary>
    /// 添加链接
    /// </summary>
    /// <param name="_gdv"></param>
    void AddHyperLink(GridView _gdv)
    {
        string DepartmentType = this.drpType.SelectedValue;
        string StartDate = this.drpMonthDateStart.SelectedValue;
        string EndDate = this.drpMonthDateEnd.SelectedValue;
        string state = string.Empty;
        #region 添加部门计划链接
        if (_gdv.Equals(this.gdvMonthDepartment))
        {
            //是否重点
            string isEmphasis = "F";
            for (int i = 0; i < this.gdvMonthDepartment.Rows.Count; i++)
            {
                if (this.gdvMonthDepartment.Rows[i].Cells[1].Text != "计划完成百分比"
                    && this.gdvMonthDepartment.Rows[i].Cells[1].Text != "计划完成合计"
                    && this.gdvMonthDepartment.Rows[i].Cells[1].Text != "公司完成合计"
                    && this.gdvMonthDepartment.Rows[i].Cells[1].Text != "公司完成百分比"
                    && this.gdvMonthDepartment.Rows[i].Cells[2].Text != "&nbsp;")
                {

                    //计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[2].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=all' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[2].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[2].Text + "</a>";
                    }
                    //重点计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[3].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=all' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[3].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[3].Text + "</a>";
                    }
                    //圆满完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[4].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=4' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[4].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[4].Text + "</a>";
                    }

                    //重点圆满完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[5].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=4' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[5].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[5].Text + "</a>";
                    }
                    //顺利完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[6].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=5' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[6].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[6].Text + "</a>";
                    }

                    //重点顺利完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[7].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=5' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[7].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[7].Text + "</a>";
                    }

                    //有障碍计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[8].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=6' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[8].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[8].Text + "</a>";
                    }
                    //重点有障碍计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[9].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=6' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[9].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[9].Text + "</a>";
                    }
                    //失控完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[10].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=7' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[10].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[10].Text + "</a>";
                    }
                    //重点失控计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[11].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=7' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[11].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[11].Text + "</a>";
                    }
                    //调整计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[12].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=8' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[12].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[12].Text + "</a>";
                    }
                    //调整计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartment.Rows[i].Cells[13].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartment.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=8' target='_blank'>";
                        this.gdvMonthDepartment.Rows[i].Cells[13].Text = _url + this.gdvMonthDepartment.Rows[i].Cells[13].Text + "</a>";
                    }

                }
            }
        }
        #endregion

        #region 添加中心计划链接
        if (_gdv.Equals(this.gdvMonthDepartmentCenter))
        {
            //是否重点
            string isEmphasis = "F";
            for (int i = 0; i < this.gdvMonthDepartmentCenter.Rows.Count; i++)
            {
                if (this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text != "计划完成百分比"
                    && this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text != "计划完成合计"
                    && this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text != "公司完成合计"
                    && this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text != "公司完成百分比"
                    && this.gdvMonthDepartmentCenter.Rows[i].Cells[2].Text != "&nbsp;")
                {

                    //计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[2].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=all' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[2].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[2].Text + "</a>";
                    }
                    //重点计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[3].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=all' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[3].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[3].Text + "</a>";
                    }
                    //圆满完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[4].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=4' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[4].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[4].Text + "</a>";
                    }

                    //重点圆满完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[5].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=4' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[5].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[5].Text + "</a>";
                    }
                    //顺利完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[6].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=5' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[6].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[6].Text + "</a>";
                    }

                    //重点顺利完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[7].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=5' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[7].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[7].Text + "</a>";
                    }

                    //有障碍计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[8].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=6' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[8].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[8].Text + "</a>";
                    }
                    //重点有障碍计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[9].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=6' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[9].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[9].Text + "</a>";
                    }
                    //失控完成计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[10].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=7' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[10].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[10].Text + "</a>";
                    }
                    //重点失控计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[11].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=7' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[11].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[11].Text + "</a>";
                    }
                    //调整计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[12].Text) > 0)
                    {
                        isEmphasis = "F";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=8' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[12].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[12].Text + "</a>";
                    }
                    //调整计划总数                    
                    if (Convert.ToInt32(this.gdvMonthDepartmentCenter.Rows[i].Cells[13].Text) > 0)
                    {
                        isEmphasis = "T";
                        string DepartmentName = Server.UrlEncode(this.gdvMonthDepartmentCenter.Rows[i].Cells[1].Text);
                        string _url = "<a href='ViewPlanForMonthWeek.aspx?PlanType=1&StartDate=";
                        _url += StartDate + "&EndDate=" + EndDate + "&DepartmentName=";
                        _url += DepartmentName;
                        _url += "&isEmphasis=" + isEmphasis;
                        _url += "&DepartmentType=" + DepartmentType;
                        _url += "&state=8' target='_blank'>";
                        this.gdvMonthDepartmentCenter.Rows[i].Cells[13].Text = _url + this.gdvMonthDepartmentCenter.Rows[i].Cells[13].Text + "</a>";
                    }

                }
            }
        }
        #endregion
    }

    /// <summary>
    /// 处理中心样式
    /// </summary>
    /// <param name="_gridView"></param>
    void ProcessCenter(GridView _gridView)
    {
        _gridView.Columns[4].HeaderStyle.BackColor = System.Drawing.Color.FromName("#00C0C0");
        _gridView.Columns[5].HeaderStyle.BackColor = System.Drawing.Color.FromName("#00C0C0");
        _gridView.Columns[6].HeaderStyle.BackColor = System.Drawing.Color.FromName("#00C000");
        _gridView.Columns[7].HeaderStyle.BackColor = System.Drawing.Color.FromName("#00C000");
        _gridView.Columns[8].HeaderStyle.BackColor = System.Drawing.Color.Yellow;
        _gridView.Columns[9].HeaderStyle.BackColor = System.Drawing.Color.Yellow;
        _gridView.Columns[10].HeaderStyle.BackColor = System.Drawing.Color.Red;
        _gridView.Columns[11].HeaderStyle.BackColor = System.Drawing.Color.Red;
        _gridView.Columns[12].HeaderStyle.BackColor = System.Drawing.Color.FromName("#c0c0c0");
        _gridView.Columns[13].HeaderStyle.BackColor = System.Drawing.Color.FromName("#c0c0c0");
        _gridView.Columns[4].ItemStyle.BackColor = System.Drawing.Color.FromName("#00C0C0");
        _gridView.Columns[5].ItemStyle.BackColor = System.Drawing.Color.FromName("#00C0C0");
        _gridView.Columns[6].ItemStyle.BackColor = System.Drawing.Color.FromName("#00C000");
        _gridView.Columns[7].ItemStyle.BackColor = System.Drawing.Color.FromName("#00C000");
        _gridView.Columns[8].ItemStyle.BackColor = System.Drawing.Color.Yellow;
        _gridView.Columns[9].ItemStyle.BackColor = System.Drawing.Color.Yellow;
        _gridView.Columns[10].ItemStyle.BackColor = System.Drawing.Color.Red;
        _gridView.Columns[11].ItemStyle.BackColor = System.Drawing.Color.Red;
        _gridView.Columns[12].ItemStyle.BackColor = System.Drawing.Color.FromName("#c0c0c0");
        _gridView.Columns[13].ItemStyle.BackColor = System.Drawing.Color.FromName("#c0c0c0");

    }

    /// <summary>
    /// 处理部门样式
    /// </summary>
    /// <param name="_gridView"></param>
    void Process(GridView _gridView)
    {
        _gridView.Columns[4].HeaderStyle.BackColor = System.Drawing.Color.FromName("#00C0C0");
        _gridView.Columns[5].HeaderStyle.BackColor = System.Drawing.Color.FromName("#00C0C0");
        _gridView.Columns[6].HeaderStyle.BackColor = System.Drawing.Color.FromName("#00C000");
        _gridView.Columns[7].HeaderStyle.BackColor = System.Drawing.Color.FromName("#00C000");
        _gridView.Columns[8].HeaderStyle.BackColor = System.Drawing.Color.Yellow;
        _gridView.Columns[9].HeaderStyle.BackColor = System.Drawing.Color.Yellow;
        _gridView.Columns[10].HeaderStyle.BackColor = System.Drawing.Color.Red;
        _gridView.Columns[11].HeaderStyle.BackColor = System.Drawing.Color.Red;
        _gridView.Columns[12].HeaderStyle.BackColor = System.Drawing.Color.FromName("#c0c0c0");
        _gridView.Columns[13].HeaderStyle.BackColor = System.Drawing.Color.FromName("#c0c0c0");
        _gridView.Columns[4].ItemStyle.BackColor = System.Drawing.Color.FromName("#00C0C0");
        _gridView.Columns[5].ItemStyle.BackColor = System.Drawing.Color.FromName("#00C0C0");
        _gridView.Columns[6].ItemStyle.BackColor = System.Drawing.Color.FromName("#00C000");
        _gridView.Columns[7].ItemStyle.BackColor = System.Drawing.Color.FromName("#00C000");
        _gridView.Columns[8].ItemStyle.BackColor = System.Drawing.Color.Yellow;
        _gridView.Columns[9].ItemStyle.BackColor = System.Drawing.Color.Yellow;
        _gridView.Columns[10].ItemStyle.BackColor = System.Drawing.Color.Red;
        _gridView.Columns[11].ItemStyle.BackColor = System.Drawing.Color.Red;
        _gridView.Columns[12].ItemStyle.BackColor = System.Drawing.Color.FromName("#c0c0c0");
        _gridView.Columns[13].ItemStyle.BackColor = System.Drawing.Color.FromName("#c0c0c0");
        System.Drawing.Color[] _color = new System.Drawing.Color[5];
        _color[0] = System.Drawing.Color.Gray;
        _color[1] = System.Drawing.Color.Cornsilk;
        _color[2] = System.Drawing.Color.Brown;
        _color[3] = System.Drawing.Color.Orange;
        _color[4] = System.Drawing.Color.Purple;
        _gridView.Rows[1].Cells[0].BackColor = _color[0];
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            if (_gridView.Rows[i].Cells[1].Text == "计划完成百分比" || _gridView.Rows[i].Cells[1].Text == "公司完成百分比")
            {
                double percent = Convert.ToDouble(_gridView.Rows[i].Cells[3].Text);
                percent = percent * 100;
                percent = Convert.ToDouble(_gridView.Rows[i].Cells[5].Text);

                _gridView.Rows[i].Cells[5].Text = percent.ToString("P");
                percent = Convert.ToDouble(_gridView.Rows[i].Cells[4].Text);

                _gridView.Rows[i].Cells[4].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[6].Text);

                _gridView.Rows[i].Cells[6].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[7].Text);
                _gridView.Rows[i].Cells[7].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[8].Text);
                _gridView.Rows[i].Cells[8].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[9].Text);
                _gridView.Rows[i].Cells[9].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[10].Text);
                _gridView.Rows[i].Cells[10].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[11].Text);
                _gridView.Rows[i].Cells[11].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[12].Text);
                _gridView.Rows[i].Cells[12].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[13].Text);
                _gridView.Rows[i].Cells[13].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[14].Text);
                _gridView.Rows[i].Cells[14].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[15].Text);
                _gridView.Rows[i].Cells[15].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[16].Text);
                _gridView.Rows[i].Cells[16].Text = percent.ToString("P");

                percent = Convert.ToDouble(_gridView.Rows[i].Cells[17].Text);
                _gridView.Rows[i].Cells[17].Text = percent.ToString("P");

            }
        }
        int _index = 0;
        for (int i = 1; i < _gridView.Rows.Count; i++)
        {

            if (_gridView.Rows[i].Cells[1].Text == "计划完成合计")
            {
                _gridView.Rows[i].BackColor = _color[_index];
                _gridView.Rows[i].Cells[3].BackColor = _color[_index];
                _gridView.Rows[i].Cells[4].BackColor = _color[_index];
                _gridView.Rows[i].Cells[5].BackColor = _color[_index];
                _gridView.Rows[i].Cells[6].BackColor = _color[_index];
                _gridView.Rows[i].Cells[7].BackColor = _color[_index];
                _gridView.Rows[i].Cells[8].BackColor = _color[_index];
                _gridView.Rows[i].Cells[9].BackColor = _color[_index];
                _gridView.Rows[i].Cells[10].BackColor = _color[_index];
                _gridView.Rows[i].Cells[11].BackColor = _color[_index];
                _gridView.Rows[i].Cells[12].BackColor = _color[_index];
                _gridView.Rows[i].Cells[13].BackColor = _color[_index];
                _gridView.Rows[i].Cells[14].BackColor = _color[_index];
                _gridView.Rows[i].Cells[15].BackColor = _color[_index];
                _gridView.Rows[i].Cells[16].BackColor = _color[_index];
                _gridView.Rows[i].Cells[17].BackColor = _color[_index];
                _gridView.Rows[i].Cells[18].BackColor = _color[_index];
                _gridView.Rows[i].Cells[19].BackColor = _color[_index];
            }
            if (_gridView.Rows[i].Cells[1].Text == "计划完成百分比")
            {
                _gridView.Rows[i].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[3].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[5].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[4].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[6].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[7].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[8].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[9].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[10].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[11].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[12].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[13].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[14].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[15].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[16].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[17].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[18].BackColor = _gridView.Rows[i - 1].BackColor;
                _gridView.Rows[i].Cells[19].BackColor = _gridView.Rows[i - 1].BackColor;
                _index++;
                if (_index > _color.Length - 1)
                {
                    _index = 0;
                }
                _gridView.Rows[i + 1].Cells[0].BackColor = _color[_index];
            }
        }
        _gridView.Rows[_gridView.Rows.Count - 3].Cells[0].BackColor = new System.Drawing.Color();
        //_gridView.Rows[_gridView.Rows.Count - 3].Cells[3].BackColor = System.Drawing.Color.FromName("#ffffff");

        _gridView.Rows[_gridView.Rows.Count - 1].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[3].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[4].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[5].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[6].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[7].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[8].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[9].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[10].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[11].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[12].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[13].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[14].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[15].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[16].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 1].Cells[17].BackColor = System.Drawing.Color.Red;

        _gridView.Rows[_gridView.Rows.Count - 2].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[3].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[4].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[5].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[6].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[7].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[8].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[9].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[10].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[11].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[12].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[13].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[14].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[15].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[16].BackColor = System.Drawing.Color.Red;
        _gridView.Rows[_gridView.Rows.Count - 2].Cells[17].BackColor = System.Drawing.Color.Red;

        #region 处理计划占比
        //double _Count = Convert.ToInt32(_gridView.Rows[_gridView.Rows.Count - 3].Cells[2].Text);

        //double _Plan = 0.0;

        //if (_Count != 0)
        //{
        //    _Plan = 1 / _Count;
        //}
        //_Plan = _Plan * 100;
        //_gridView.Rows[_gridView.Rows.Count - 1].Cells[2].Text = _Plan.ToString("0.10") + "%";
        #endregion
    }


    /// <summary>
    /// 合并同一列相同值得行
    /// </summary>
    /// <param name="_gridView"></param>
    /// <param name="_cellNum"></param>
    void MergeRow(GridView _gridView, int _cellNum)
    {
        int i = 0, rowSpanNum = 1;
        //遍历GridView
        while (i < _gridView.Rows.Count - 1)
        {
            //获得当前行
            GridViewRow gvr = _gridView.Rows[i];
            for (++i; i < _gridView.Rows.Count; i++)
            {
                //获得下一行
                GridViewRow gvrNext = _gridView.Rows[i];
                if (gvr.Cells[_cellNum].Text == gvrNext.Cells[_cellNum].Text)
                {
                    gvrNext.Cells[_cellNum].Visible = false;
                    rowSpanNum++;
                }
                else
                {
                    gvr.Cells[_cellNum].RowSpan = rowSpanNum;
                    rowSpanNum = 1;
                    break;
                }
                //遍历完毕进行合并
                if (i == _gridView.Rows.Count - 1)
                {
                    gvr.Cells[_cellNum].RowSpan = rowSpanNum;
                }
            }
        }
    }


    /// <summary>
    /// GridView行绑定事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvMonthDepartment_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1 && (e.Row.Cells[1].Text != "计划完成合计" && e.Row.Cells[1].Text != "计划完成百分比") && e.Row.RowIndex != -1 && (e.Row.Cells[1].Text != "公司完成合计" && e.Row.Cells[1].Text != "公司完成百分比"))
        {

            if (Convert.ToDouble(e.Row.Cells[4].Text) != 0)
            {

                e.Row.Cells[18].Text = (Convert.ToDouble(e.Row.Cells[4].Text) / (Convert.ToDouble(e.Row.Cells[2].Text) - Convert.ToDouble(e.Row.Cells[12].Text))).ToString("p");
            }
            else
            {
                e.Row.Cells[18].Text = "0%";
            }

            if (Convert.ToDouble(e.Row.Cells[5].Text) != 0)
            {
                e.Row.Cells[19].Text = (Convert.ToDouble(e.Row.Cells[5].Text) / (Convert.ToDouble(e.Row.Cells[3].Text) - Convert.ToDouble(e.Row.Cells[13].Text))).ToString("p");

            }
            else
            {
                e.Row.Cells[19].Text = "0%";
            }

        }
    }

    /// <summary>
    /// 导出Excel
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcel_Click(object sender, EventArgs e)
    {
        GridView[] _gridView = new GridView[1];
        if (this.drpType.SelectedValue == "0")
        {
            _gridView[0] = this.gdvMonthDepartmentCenter;
            Utility.Comm.MonthCenterToExcel(GridViewToDataTable(_gridView)[0], this.drpQuarterDateStart.SelectedItem.Text + this.drpMonthDateStart.SelectedItem.Text + "－" + this.drpQuarterDateEnd.SelectedItem.Text + this.drpMonthDateEnd.SelectedItem.Text);
        }
        else
        {
            _gridView[0] = this.gdvMonthDepartment;
            Utility.Comm.MonthDepartmentToExcel(GridViewToDataTable(_gridView)[0], this.drpQuarterDateStart.SelectedItem.Text + this.drpMonthDateStart.SelectedItem.Text + "－" + this.drpQuarterDateEnd.SelectedItem.Text + this.drpMonthDateEnd.SelectedItem.Text);
        }
    }

    /// <summary>
    /// GridView转DataTable
    /// </summary>
    DataTable[] GridViewToDataTable(GridView[] _sourceGridView)
    {
        DataTable[] _targetDataTable = new DataTable[_sourceGridView.Length];
        for (int i = 0; i < _targetDataTable.Length; i++)
        {
            _targetDataTable[i] = new DataTable();
            DataColumn dc = new DataColumn();
            GridViewRow gr = _sourceGridView[i].HeaderRow;
            //根据源GridView循环创建目标DataTable列
            for (int j = 0; j < gr.Cells.Count; j++)
            {
                //if (gr.Cells[j].Visible == true)
                //{
                if (gr.Cells[j].Text == "名称" && j == 1)
                { dc = new DataColumn("部门"); }
                else
                {
                    dc = new DataColumn(gr.Cells[j].Text);
                }
                _targetDataTable[i].Columns.Add(dc);
            }
            //根据源GridView循环创建目标DataTable行
            for (int j = 0; j < _sourceGridView[i].Rows.Count; j++)
            {
                DataRow dr = _targetDataTable[i].NewRow();
                for (int k = 0; k < gr.Cells.Count; k++)
                {

                    if (k < _targetDataTable[i].Columns.Count)
                    {

                        dr[k] = _sourceGridView[i].Rows[j].Cells[k].Text;


                    }

                }
                _targetDataTable[i].Rows.Add(dr);
            }

        }
        return _targetDataTable;
    }

    protected void gdvMonthDepartment_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);

            TableCellCollection cells = e.Row.Cells;
            cells[0].ColumnSpan = 2;
            cells[1].Visible = false;
            #region
            this.gdvMonthDepartment.Controls[0].Controls.AddAt(0, rowHeader);
            TableCell headerCellMonth = new TableCell();
            headerCellMonth.Text = "";
            headerCellMonth.ColumnSpan = 2;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "完成计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "顺利进行计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "有障碍计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "失控计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "调整计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "完成等级";
            headerCellMonth.ColumnSpan = 4;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "计划完成率";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            rowHeader.Visible = true;
            this.gdvMonthDepartment.Controls[0].Controls.AddAt(0, rowHeader);
            #endregion
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (this.drpType.SelectedItem.Text != "按部门查询")
            {
                GridViewRow drowHeader = new GridViewRow(e.Row.RowIndex, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
                TableCellCollection cells = e.Row.Cells;
                cells[0].ColumnSpan = 2;
                cells[1].Visible = false;
            }
        }
    }

    /// <summary>
    /// 中心行绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvMonthDepartmentCenter_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            if (Convert.ToDouble(e.Row.Cells[4].Text) != 0)
            {
                e.Row.Cells[14].Text = (Convert.ToDouble(e.Row.Cells[4].Text) / (Convert.ToDouble(e.Row.Cells[2].Text) - Convert.ToDouble(e.Row.Cells[12].Text))).ToString("p");
            }
            else
            {
                e.Row.Cells[14].Text = "0%";
            }

            if (Convert.ToDouble(e.Row.Cells[5].Text) != 0)
            {
                e.Row.Cells[15].Text = (Convert.ToDouble(e.Row.Cells[5].Text) / (Convert.ToDouble(e.Row.Cells[3].Text) - Convert.ToDouble(e.Row.Cells[13].Text))).ToString("p");

            }
            else
            {
                e.Row.Cells[15].Text = "0%";
            }

        }
    }

    /// <summary>
    /// 中心行创建
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvMonthDepartmentCenter_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);

            TableCellCollection cells = e.Row.Cells;
            cells[0].ColumnSpan = 2;
            cells[1].Visible = false;
            #region
            this.gdvMonthDepartmentCenter.Controls[0].Controls.AddAt(0, rowHeader);
            TableCell headerCellMonth = new TableCell();
            headerCellMonth.Text = "";
            headerCellMonth.ColumnSpan = 2;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "完成计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "顺利进行计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "有障碍计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "失控计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "调整计划数";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            headerCellMonth = new TableCell();
            headerCellMonth.Text = "计划完成率";
            headerCellMonth.ColumnSpan = 2;
            headerCellMonth.HorizontalAlign = HorizontalAlign.Center;
            rowHeader.Cells.Add(headerCellMonth);

            rowHeader.Visible = true;
            this.gdvMonthDepartmentCenter.Controls[0].Controls.AddAt(0, rowHeader);
            #endregion
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (this.drpType.SelectedItem.Text != "按部门查询")
            {
                GridViewRow drowHeader = new GridViewRow(e.Row.RowIndex, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
                TableCellCollection cells = e.Row.Cells;
                cells[0].ColumnSpan = 2;
                cells[1].Visible = false;
            }
        }
    }
}
